<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>远程调用超时设置指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
        }
        .highlight-text {
            background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="gradient-bg text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <i class="fas fa-clock floating-icon text-6xl mb-6 opacity-80"></i>
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">远程调用超时设置</h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                    掌握分布式系统的时间艺术，让服务间通信更加可靠高效
                </p>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 px-6">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <div class="flex items-start mb-6">
                    <i class="fas fa-info-circle text-3xl text-purple-600 mr-4 mt-1"></i>
                    <div>
                        <h2 class="text-3xl font-bold mb-4 serif-font">为什么超时设置如此重要？</h2>
                        <p class="text-lg text-gray-700 leading-relaxed">
                            设置远程调用的超时时间是确保分布式系统中服务间通信的可靠性和响应时间的一项关键措施。合理的超时设置可以防止因调用卡顿或异常导致的资源占用过多，从而影响系统性能。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section class="py-12 px-6 bg-gray-100">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12 serif-font">超时设置架构概览</h2>
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <div class="mermaid">
                    graph TD
                        A[客户端应用] --> B{选择调用方式}
                        B --> C[HTTP客户端]
                        B --> D[RPC框架]
                        B --> E[Spring Cloud]
                        B --> F[Netty]
                        
                        C --> G[Apache HttpClient]
                        C --> H[OkHttp]
                        C --> I[RestTemplate]
                        
                        D --> J[Dubbo]
                        D --> K[gRPC]
                        
                        E --> L[Feign]
                        E --> M[Gateway]
                        
                        F --> N[Channel配置]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </div>
    </section>

    <!-- HTTP Client Section -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="flex items-center mb-12">
                <i class="fas fa-globe text-4xl text-purple-600 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">1. HTTP 客户端超时设置</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8">
                <!-- Apache HttpClient -->
                <div class="bg-white rounded-xl shadow-lg card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-feather text-2xl text-orange-500 mr-3"></i>
                            <h3 class="text-xl font-bold">Apache HttpClient</h3>
                        </div>
                        <div class="code-block p-4 text-sm">
                            <pre><code>RequestConfig config = RequestConfig.custom()
    .setConnectTimeout(5000)  // 连接超时
    .setSocketTimeout(5000)   // 读取数据超时
    .build();

CloseableHttpClient client = HttpClients.custom()
    .setDefaultRequestConfig(config)
    .build();</code></pre>
                        </div>
                    </div>
                </div>

                <!-- OkHttp -->
                <div class="bg-white rounded-xl shadow-lg card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-square text-2xl text-green-500 mr-3"></i>
                            <h3 class="text-xl font-bold">OkHttp</h3>
                        </div>
                        <div class="code-block p-4 text-sm">
                            <pre><code>OkHttpClient client = new OkHttpClient.Builder()
    .connectTimeout(5, TimeUnit.SECONDS)
    .readTimeout(5, TimeUnit.SECONDS)
    .writeTimeout(5, TimeUnit.SECONDS)
    .build();</code></pre>
                        </div>
                    </div>
                </div>

                <!-- Spring RestTemplate -->
                <div class="bg-white rounded-xl shadow-lg card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-leaf text-2xl text-green-600 mr-3"></i>
                            <h3 class="text-xl font-bold">Spring RestTemplate</h3>
                        </div>
                        <div class="code-block p-4 text-sm">
                            <pre><code>HttpComponentsClientHttpRequestFactory factory = 
    new HttpComponentsClientHttpRequestFactory();
factory.setConnectTimeout(5000);
factory.setReadTimeout(5000);

RestTemplate restTemplate = 
    new RestTemplate(factory);</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- RPC Framework Section -->
    <section class="py-16 px-6 bg-gray-100">
        <div class="max-w-6xl mx-auto">
            <div class="flex items-center mb-12">
                <i class="fas fa-network-wired text-4xl text-purple-600 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">2. RPC 框架超时设置</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Dubbo -->
                <div class="bg-white rounded-xl shadow-lg p-8">
                    <div class="flex items-center mb-6">
                        <i class="fas fa-cube text-3xl text-blue-500 mr-4"></i>
                        <h3 class="text-2xl font-bold">Dubbo</h3>
                    </div>
                    <p class="text-gray-600 mb-4">通过 XML 配置或注解方式设置服务调用超时</p>
                    <div class="code-block p-4">
                        <pre><code>&lt;dubbo:reference 
    id="someService" 
    interface="com.example.SomeService" 
    timeout="5000" /&gt;</code></pre>
                    </div>
                </div>

                <!-- gRPC -->
                <div class="bg-white rounded-xl shadow-lg p-8">
                    <div class="flex items-center mb-6">
                        <i class="fas fa-server text-3xl text-indigo-500 mr-4"></i>
                        <h3 class="text-2xl font-bold">gRPC</h3>
                    </div>
                    <p class="text-gray-600 mb-4">通过 Channel 和 Stub 配置超时时间</p>
                    <div class="code-block p-4">
                        <pre><code>ManagedChannel channel = ManagedChannelBuilder
    .forAddress("localhost", 8080)
    .idleTimeout(5, TimeUnit.SECONDS)
    .build();

SomeServiceBlockingStub stub = SomeServiceGrpc
    .newBlockingStub(channel)
    .withDeadlineAfter(5, TimeUnit.SECONDS);</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Spring Cloud Section -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="flex items-center mb-12">
                <i class="fas fa-cloud text-4xl text-purple-600 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">3. Spring Cloud 超时设置</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Feign -->
                <div class="bg-white rounded-xl shadow-lg p-8">
                    <div class="flex items-center mb-6">
                        <i class="fas fa-feather-alt text-3xl text-pink-500 mr-4"></i>
                        <h3 class="text-2xl font-bold">Feign</h3>
                    </div>
                    <div class="code-block p-4">
                        <pre><code>feign:
  client:
    config:
      default:
        connectTimeout: 5000   # 连接超时
        readTimeout: 5000      # 读取超时</code></pre>
                    </div>
                </div>

                <!-- Spring Cloud Gateway -->
                <div class="bg-white rounded-xl shadow-lg p-8">
                    <div class="flex items-center mb-6">
                        <i class="fas fa-door-open text-3xl text-purple-500 mr-4"></i>
                        <h3 class="text-2xl font-bold">Spring Cloud Gateway</h3>
                    </div>
                    <div class="code-block p-4">
                        <pre><code>spring:
  cloud:
    gateway:
      httpclient:
        connect-timeout: 5000  # 连接超时
        response-timeout: 5000 # 响应超时</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Netty Section -->
    <section class="py-16 px-6 bg-gray-100">
        <div class="max-w-6xl mx-auto">
            <div class="flex items-center mb-12">
                <i class="fas fa-bolt text-4xl text-purple-600 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">4. Netty 超时设置</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-lg p-8 max-w-3xl mx-auto">
                <p class="text-gray-600 mb-6">使用 Netty 进行网络编程时，通过 ChannelOption 控制超时</p>
                <div class="code-block p-6">
                    <pre><code>Bootstrap bootstrap = new Bootstrap();
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000); // 连接超时
bootstrap.option(ChannelOption.SO_TIMEOUT, 5000);             // 读写超时</code></pre>
                </div>
            </div>
        </div>
    </section>

    <!-- Best Practices Section -->
    <section class="py-16 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="flex items-center mb-12">
                <i class="fas fa-lightbulb text-4xl text-yellow-500 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">5. 最佳实践建议</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="text-center mb-6">
                        <i class="fas fa-chart-line text-5xl text-blue-500 mb-4"></i>
                        <h3 class="text-xl font-bold mb-3">评估服务性能</h3>
                    </div>
                    <p class="text-gray-600">
                        根